package com.zhai.netty.thread.chapter01;

public class DeadLockDemon {
	
	private static String ALock = "A";
	
	private static String BLock = "B";
	
	public static void main(String[] args) {
		new DeadLockDemon().deadLock();
	}
	
	private void deadLock(){
		Thread thread1 = new Thread(new Runnable() {
			public void run() {
				synchronized (ALock) {
					try {
						System.out.println("线程休眠 2秒钟");
						Thread.sleep(2000);
					} catch (Exception e) {
						e.printStackTrace();
					}
					synchronized (BLock) {
						System.out.println("1");
					}
				}
				
			}
		});
		
		Thread thread2 = new Thread(new Runnable() {
			public void run() {
				synchronized (BLock) {
					synchronized (ALock) {
						try {
							System.out.println("线程B休眠2秒钟：currentTime = "+System.currentTimeMillis());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}
			}
		});
		
		thread1.start();
		thread2.start();
	}
}
